package com.happyfamily.springboot.crowdsourcingplatform.service.weng.impl;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dao.weng.LogDao;
import com.happyfamily.springboot.crowdsourcingplatform.dto.LogDto;
import com.happyfamily.springboot.crowdsourcingplatform.model.OperationLog;
import com.happyfamily.springboot.crowdsourcingplatform.service.weng.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class LogServiceImpl implements LogService
{
	@Autowired
	LogDao logDao;

	@Override
	public Results<OperationLog> getAllLogsByPage(Integer startPosition, Integer limit)
	{
		return Results.success(logDao.countAllLogs().intValue(), logDao.getAllLogsByPage(startPosition, limit));
	}

	@Override
	public int deleteLog(Integer id)
	{
		return logDao.deleteLog(id);
	}

	@Override
	public LogDto getLogById(Integer id)
	{
		return logDao.getById(id);
	}

	@Override
	public Results<OperationLog> getLogByFuzzy(String logDescribe, String operationType, String startTime, String endTime, Integer startPosition, Integer limit)
	{
		return Results.success(logDao.getLogByFuzzy(logDescribe, operationType, startTime, endTime).intValue(), logDao.getLogByFuzzyPage(logDescribe, operationType, startTime, endTime, startPosition, limit));
	}

	@Override
	public int insert(OperationLog operationLog)
	{
		return logDao.insert(operationLog);
	}
}
